﻿namespace Web.Control.WWW.Resources
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections;
    using System.Collections.Generic;  

    using Lx.Web.Common.ControlsUI;
    using BLF.WWW_WWW.Resource;
    using Model.WWW_WWW.Resource;     

    /// <summary>
    /// Default 的摘要说明
    /// </summary>
    public class Default : BaseControl
    {
        /// <summary>
        /// 当前会员号
        /// </summary>
        protected string Memberno = "";
        /// <summary>
        /// 当前所选择学习语言
        /// </summary>
        protected string CurrentLearn = "english";
        /// <summary>
        /// 当前所用语言
        /// </summary>
        protected string CurrentSpeak = "";
        /// <summary>
        /// 绑定用户学习列表
        /// </summary>
        protected Repeater userRList;
        /// <summary>
        /// 绑定学习资源列表
        /// </summary>
        protected Repeater LeaRList;
        protected Repeater SpeakRList;
        /// <summary>
        /// 绑定最受欢迎资源列表
        /// </summary>
        protected Repeater PopRList;
        protected Literal litScript;
        /// <summary>
        /// 学习资源列表数量
        /// </summary>
        protected int LearnRCount = 0;
        /// <summary>
        /// 最受欢迎资源列表数量
        /// </summary>
        protected int PopularRCount = 0;
        /// <summary>
        /// 所用语言资源数量
        /// </summary>
        protected int speakRCount = 0;
        
        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;            
            List<TResourcesPageModel> uRList;
            List<TResourcesPageModel> lRList;
            List<TResourcesPageModel> sRList;
            List<TResourcesModel> pRList;            
            if (Request["learn"] != null || Request["speak"] != null)
            {
                CurrentLearn = Request["learn"];
                CurrentSpeak = Request["speak"];
                if (string.IsNullOrEmpty(CurrentLearn)) CurrentLearn = "";
                if (string.IsNullOrEmpty(CurrentSpeak)) CurrentSpeak = "";
                ArrayList arrayList = Resources.GetResourcesList(Memberno, CurrentLearn, CurrentSpeak);
                //(0:List(TResourcesPageModel)当前用户学习资源,1:List(TResourcesPageModel)使用语言学习语言资源,
                // 2:List(TResourcesPageModel)学习语言学习资源,3:List(TResourcesModel)学习语言最受欢迎的资源)
                uRList = arrayList[0] as List<TResourcesPageModel>;
                sRList = arrayList[1] as List<TResourcesPageModel>;
                lRList = arrayList[2] as List<TResourcesPageModel>;
                pRList = arrayList[3] as List<TResourcesModel>;
                LearnRCount = lRList.Count;
                speakRCount = sRList.Count;
                PopularRCount = pRList.Count;
                if (speakRCount != 0)
                {
                    SpeakRList.DataSource = sRList;
                    SpeakRList.DataBind();
                }
            }
            else
            {
                ArrayList outList;
                Model.CommonMessage commonMessage = Resources.GetResources(Memberno, out outList);
                uRList = outList[0] as List<TResourcesPageModel>;
                lRList = outList[1] as List<TResourcesPageModel>;
                pRList = outList[2] as List<TResourcesModel>;
                CurrentLearn = (string)outList[3];
                LearnRCount = lRList.Count;
                PopularRCount = pRList.Count;
            }
            if (Memberno != "")
            {
                userRList.DataSource = uRList;
                userRList.DataBind();
            }            
            if (LearnRCount != 0)
            {                
                LeaRList.DataSource = lRList;
                LeaRList.DataBind();
            }
            if (PopularRCount != 0)
            {
                PopRList.DataSource = pRList;
                PopRList.DataBind();
            }            
            base.OnLoad(e);
        }
    }
}
